package com.hexinfo.dmpro.monitor.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.annotation.Log;
import com.hexinfo.dmpro.common.base.Page;
import com.hexinfo.dmpro.monitor.model.cm.ResourceBaseReqModel;
import com.hexinfo.dmpro.monitor.service.CmImpalaService;
import com.hexinfo.dmpro.monitor.service.CmYarnService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author peng
 * @date 2021/10/14 9:36
 */
@RestController
@RequestMapping("/monitor_api/cmResouce")
public class CmResourceController {

    @Autowired
    private CmImpalaService cmImpalaService;

    @Autowired
    private CmYarnService cmYarnService;

    /**
     * 查询impala资源使用top信息
     * @param model
     * @return
     */
    @Log("查询impala资源使用top信息")
    @PostMapping(value = "/selImpalaPoolTop")
    public ResponseEntity<Object> selImpalaPoolTop(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmImpalaService.selImpalaPoolTop(model), HttpStatus.OK);
    }

    /**
     * 查询impala单个资源信息
     * @param model
     * @return
     */
    @Log("查询impala单个资源信息")
    @PostMapping(value = "/selImpalaPoolSyl")
    public ResponseEntity<Object> selImpalaPoolSyl(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmImpalaService.selImpalaPoolSyl(model), HttpStatus.OK);
    }

    /**
     * 查询impala资源池统计信息
     * @param model
     * @return
     */
    @Log("查询impala资源池统计信息")
    @PostMapping(value = "/selImpalaPoolAllCount")
    public ResponseEntity<Object> selImpalaPoolAllCount(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmImpalaService.selImpalaPoolAllCount(model), HttpStatus.OK);
    }

    /**
     * 查询impala资源池统计信息
     * @param model
     * @return
     */
    @Log("查询impala资源池统计信息列表")
    @GetMapping(value = "/selImpalaPoolAll")
    public ResponseEntity<Object> selImpalaPoolAll(Page page,ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmImpalaService.selImpalaPoolAll(page,model), HttpStatus.OK);
    }

    /**
     * 查询impala资源池异常统计信息
     * @param model
     * @return
     */
    @Log("查询impala资源池异常信息")
    @PostMapping(value = "/selImpalaPoolYcCount")
    public ResponseEntity<Object> selImpalaPoolYcCount(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmImpalaService.selImpalaPoolYcCount(model), HttpStatus.OK);
    }

    /**
     * 查询impala资源池异常统计信息
     * @param model
     * @return
     */
    @Log("查询impala资源池异常统计信息")
    @GetMapping(value = "/selImpalaPoolYc")
    public ResponseEntity<Object> selImpalaPoolYc(Page page,ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmImpalaService.selImpalaPoolYc(page,model), HttpStatus.OK);
    }

    @Log("查询impala资源使用信息")
    @GetMapping(value = "/selImpalaPoolDetail")
    public ResponseEntity<Object> selImpalaPoolDetail(Page page, @Param("current") int current, ResourceBaseReqModel model) {
        page.setPageIndex(current-1);
        return new ResponseEntity<>(cmImpalaService.selImpalaPoolDetail(page, model), HttpStatus.OK);
    }

    /**
     * 查询yarn资源使用top信息
     * @param model
     * @return
     */
    @Log("查询yarn资源使用top信息")
    @PostMapping(value = "/selYarnPoolTop")
    public ResponseEntity<Object> selYarnPoolTop(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmYarnService.selYarnPoolTop(model), HttpStatus.OK);
    }

    /**
     * 查询yarn 单个资源使用信息
     * @param model
     * @return
     */
    @Log("查询yarn 单个资源使用信息")
    @PostMapping(value = "/selYarnPoolSyl")
    public ResponseEntity<Object> selYarnPoolSyl(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmYarnService.selYarnPoolSyl(model), HttpStatus.OK);
    }

    /**
     * 查询yarn资源使用top  CPU信息
     * @param model
     * @return
     */
    @Log("查询yarn资源使用top信息")
    @PostMapping(value = "/selYarnCpuTop")
    public ResponseEntity<Object> selYarnCpuTop(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmYarnService.selYarnCpuTop(model), HttpStatus.OK);
    }

    /**
     * 查询yarn资源池统计信息
     * @param model
     * @return
     */
    @Log("查询yarn资源池统计信息")
    @PostMapping(value = "/selYarnPoolAllCount")
    public ResponseEntity<Object> selYarnPoolAllCount(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmYarnService.selYarnPoolAllCount(model), HttpStatus.OK);
    }

    /**
     * 查询yarn资源池统计信息
     * @param model
     * @return
     */
    @Log("查询yarn资源池统计信息列表")
    @GetMapping(value = "/selYarnPoolAll")
    public ResponseEntity<Object> selYarnPoolAll(Page page,ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmYarnService.selYarnPoolAll(page,model), HttpStatus.OK);
    }

    /**
     * 查询yarn资源池异常统计信息
     * @param model
     * @return
     */
    @Log("查询yarn资源池异常统计信息")
    @PostMapping(value = "/selYarnPoolYcCount")
    public ResponseEntity<Object> selYarnPoolYcCount(@RequestBody ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmYarnService.selYarnPoolYcCount(model), HttpStatus.OK);
    }

    /**
     * 查询yarn资源池异常统计信息
     * @param model
     * @return
     */
    @Log("查询yarn资源池异常信息")
    @GetMapping(value = "/selYarnPoolYc")
    public ResponseEntity<Object> selYarnPoolYc(Page page,ResourceBaseReqModel model) {
        return new ResponseEntity<>(cmYarnService.selYarnPoolYc(page,model), HttpStatus.OK);
    }

    @Log("查询yarn资源使用信息")
    @GetMapping(value = "/selYarnPoolDetail")
    public ResponseEntity<Object> selYarnPoolDetail(Page page, @Param("current") int current, ResourceBaseReqModel model) {
        page.setPageIndex(current-1);
        return new ResponseEntity<>(cmYarnService.selYarnPoolDetail(page, model), HttpStatus.OK);
    }

}
